﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReporterEngine;
using System.Xml.Linq;
using System.IO;

namespace ReportEngine_TestProject
{
    public static class utils
    {
        public static CIFModel GetSampleModel()
        {
            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            var actualPath = assembly.GetManifestResourceNames();

            var content = "";

            using (var str = assembly.GetManifestResourceStream("ReportEngine_TestProject.data.cif1.xml"))
            {
                using (var reader = new StreamReader(str))
                {
                    content = reader.ReadToEnd();
                }
            }

            var cif = XDocument.Parse(content);

            var cifModel = new CIFModel();

            cifModel.Parse(cif);

            return cifModel;
        }

     

        public static sQuery GetSampleUseCaseModel(CIFModel cifmodel)
        {
            var usecases = cifmodel.ModelTypes.Where(x => x.Label.ToLower() == "use case model").FirstOrDefault().Nodes;

            var result = sQuery.New(cifmodel);

            result.Elements.AddRange(usecases);
            
            return result;
        }

        public static XElement getTemplate(string name)
        {
            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            var actualPath = assembly.GetManifestResourceNames();

            var content = "";

            using (var str = assembly.GetManifestResourceStream("ReportEngine_TestProject.data." + name + ".xml"))
            {
                using (var reader = new StreamReader(str))
                {
                    content = reader.ReadToEnd();
                }
            }

            var templateDoc = XDocument.Parse(content);

            return templateDoc.Root;
        }

        public static XElement getTemplate(int order)
        {
            return getTemplate("testTemplate" + order);
        }
    }
}
